package speedball;

import javafx.animation.Animation;
import javafx.animation.KeyFrame;
import javafx.animation.KeyValue;
import javafx.animation.RotateTransition;
import javafx.animation.Timeline;
import javafx.beans.property.DoubleProperty;
import javafx.scene.Node;
import javafx.util.Duration;

public class AnimationManage {
	
	
	public static Animation setRotateAnimation( Node paramNode,Duration paramDuration) {
		return setRotateAnimation(paramDuration,false,paramNode);
	}
	public static Animation setRotateAnimation(double millis,Node... paramNode) {
		return setRotateAnimation(Duration.millis(millis),false,paramNode);
	}
	
	
	public static Animation setRotateAnimation(Duration paramDuration,boolean isCyclePause,Node... paramNodes) {
		Animation animation;
		if(isCyclePause) {
			//TODO 暂时for对RotateTransition有影响，做循环，以后再改
			RotateTransition rotateTransition =  new RotateTransition(paramDuration, null);
			rotateTransition.setCycleCount(-1);
			rotateTransition.setFromAngle(0);
//	        rotateTransition.setToAngle(360);
			rotateTransition.setToAngle(720);
			rotateTransition.setAutoReverse(true);
//			rotateTransition.play();
			animation=rotateTransition;
			
		}else {
			// Timeline旋转方式旋转没有间隔
			Timeline timeline54 = new Timeline();
	        double i = Integer.MAX_VALUE;
	        
	        for (Node node : paramNodes) {
	        	// 持续68.096年
		        timeline54.getKeyFrames().addAll(new KeyFrame(paramDuration, new KeyValue(node.rotateProperty(), 360*i)));
			}
//	        timeline54.play();
	        animation=timeline54;
		}
		return animation;
		
	}
	
	public static Animation setRotateAnimation(Duration paramDuration,boolean isCyclePause,Node node) {
		Animation animation;
		if(isCyclePause) {
			//TODO 暂时for对RotateTransition有影响，做循环，以后再改
			RotateTransition rotateTransition =  new RotateTransition(paramDuration, null);
			rotateTransition.setCycleCount(-1);
			rotateTransition.setFromAngle(0);
//	        rotateTransition.setToAngle(360);
			rotateTransition.setToAngle(720);
			rotateTransition.setAutoReverse(true);
//			rotateTransition.play();
			animation=rotateTransition;
			
		}else {
			// Timeline旋转方式旋转没有间隔
			Timeline timeline54 = new Timeline();
	        double i = Integer.MAX_VALUE;
	        	// 持续68.096年
	        //new KeyFrame(new Duration(0), new KeyValue(node.rotateProperty(), 0)), 
		        timeline54.getKeyFrames().addAll(new KeyFrame(paramDuration, new KeyValue(node.rotateProperty(), 360*i)));
//	        timeline54.play();
	        animation=timeline54;
		}
		return animation;
		
	}
	
	
//	int cycleCount=Timeline.INDEFINITE;
	
//	FadeTransition ft1 = new FadeTransition(Duration.millis(duration), gridPane);
//	ft1.setFromValue(1.0);
//	ft1.setToValue(0.0);
//	ft1.setCycleCount(cycleCount);
//	ft1.setAutoReverse(true);
//	ft1.play();
//	
//	FadeTransition ft = new FadeTransition(Duration.millis(duration), expand);
//	ft.setFromValue(1.0);
//	ft.setToValue(0.0);
//	ft.setCycleCount(cycleCount);
//	ft.setAutoReverse(true);
//	ft.play();
//
//		//创建时间�?
//		final Timeline timeline=new Timeline();
//		timeline.setCycleCount(cycleCount);//设置周期运行循环�?�?
////		timeline.setCycleCount(1);//设置周期运行循环�?�?
//		
//		timeline.setAutoReverse(true);//设置动画的自动往返效�?
//		
//		//将x的位置在500ms内移动到300�?
//		final KeyValue kv=new KeyValue(rect.widthProperty(), 0D);
//		final KeyFrame kf=new KeyFrame(Duration.millis(duration), kv);
//		//将关键帧加到时间轴中
//		timeline.getKeyFrames().add(kf);
//		
//		timeline.play();//运行
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	//将x的位置在500ms内移动到300�?
//	final KeyValue kv2=new KeyValue(rect.widthProperty(), 0D);
//	final KeyFrame kf2=new KeyFrame(Duration.millis(duration), kv2);
//	//将关键帧加到时间轴中
//	timeline2.getKeyFrames().add(kf2);
//	
//	timeline2.play();//运行
	
	
	
	
	
	
	
	
	
	
	
	
	
	
//	//将x的位置在500ms内移动到300�?
//	final KeyValue kv2=new KeyValue(rect.widthProperty(), rectangleWidth);
//	final KeyFrame kf2=new KeyFrame(Duration.millis(duration), kv2);
//	//将关键帧加到时间轴中
//	timeline2.getKeyFrames().add(kf2);
//	
//	timeline2.play();//运行
	
	
	
	//+================================水波动画
	
//////创建时间�?
//final Timeline timeline=new Timeline();
//timeline.setCycleCount(-1);//设置周期运行循环�?�?
//////timeline.setCycleCount(1);//设置周期运行循环�?�?
//
//timeline.setAutoReverse(true);//设置动画的自动往返效�?
//
////将x的位置在500ms内移动到300�?
////final KeyValue kv=new KeyValue(path.shawidthProperty(), 0D);

//final KeyValue kv=new KeyValue(path.property(), 0D);
//final KeyFrame kf=new KeyFrame(Duration.millis(400), e->setPath(root));
////将关键帧加到时间轴中
//timeline.getKeyFrames().add(kf);
//
//timeline.play();//运行
	
	
	
	
	
	
	
	
	
	
	

	//矩形的缩放效果
//    ScaleTransition scaleTransition =  new ScaleTransition(Duration.millis(500), right);
////    scaleTransition.setFromX(1);
////    scaleTransition.setFromY(1);
////    scaleTransition.setFromZ(1);
//    
//        scaleTransition.setToX(0f);
//        scaleTransition.setToY(1f);
////        scaleTransition.setFromX(0);
////        scaleTransition.setFromY(0);
//        scaleTransition.setCycleCount(1);
////
////        scaleTransition.setCycleCount(Timeline.INDEFINITE);
//        scaleTransition.setAutoReverse(true);
//        scaleTransition.play();
	
	
	
	
	
	
	
	
	
	
	
	// Apply a rotation on rect2. The rotation angle is 30 degree clockwise
	// (0, 0) is the pivot point
//	Rotate rotate = new Rotate(0, 0, 0);
//	rect.getTransforms().addAll(rotate);
	
	
	
	
	
	
	
	
	
	
	
	
	
}
